<?php

if (!defined("MCTDESIGN")) die("# ");
global $temp;
$keyword = m_htmlchars($_GET['keyword']);
$temp_search = $temp;
$temp_search->assign( 'base_tpl', "".$dir_tpl."" );
$temp_search->assign( 'key_search', "".$keyword."" );
# BEGIN : SEARCH
if (!empty($keyword)) {
	$_limit = 15;
	
	$temp_search->assign( 'sort_html', "$sort_html" );
	
	$sql = "SELECT p.*,c.cat_title FROM ".$tb_fix."_product AS p
                LEFT JOIN ".$tb_fix."_category AS c
                    ON p.pro_catid = c.cat_id 
            WHERE (p.pro_name RLIKE '^[0-9]' OR p.pro_name LIKE '%".$keyword."%' OR p.pro_name LIKE '".$keyword."%') 
            ORDER BY pro_id DESC";
	$q = $mysql->query($sql);
	$t = $mysql->num_rows($q);
	if ($t>0) {
		$_start = ($page-1) * $_limit ;
		$_end   = $page*$_limit;
		$num_pages = ceil($t/$_limit) ;
		if ($page > $num_pages) $page=$num_pages;
		if ($page < 1 ) $page=1;
		$page_view = Paginate("TimKiem/".$keyword,'',$t, $_limit, $page);
		$c=0;
		$i = 0;
		$list_product = "";
		while ($r = $mysql->fetch_array($q)) {
			if ($i>=$_start) {
				$c++;
					$list_product .= show_category_product($r,$catid="",$catparentid="");
			}
			$i++;
			if ($i>=$_end) break;
		}
			$temp_search->assign( 'page_view', "".$page_view."" );
			$temp_search->assign( 'list_product', "".$list_product."" );
		}
		else $temp_search->assign( 'list_product', "<br><br><center>Không tìm thấy sản phẩm nào.</center><br><br>" );
}
else $temp_search->assign( 'list_product', "<br><br><center>Bạn vui lòng nhập từ khóa tìm kiếm.</center><br><br>" );
# END : SEARCH
$content = $temp_search->fetch( 'product/_shop_search.mct' );


?>